package com.example.bootdemo.controller;

import com.example.bootdemo.model.User;
import com.example.bootdemo.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "用户查询")
@Slf4j
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation("根据ID查询")
    @GetMapping("/getUserById/{Id}")
    private User getUserById(@PathVariable("Id") Long id){
        log.info("/getUserById {}",id);
        return userService.queryById(id);
    }

    @GetMapping("/queryAll")
    @ApiOperation("查询所有")
    private List<User> queryAll(){
        log.error("queryAll");
        return userService.queryAll();
    }

    @PostMapping("/addUser")
    @ApiOperation("新增用户")
    @ApiImplicitParam(name = "user",required = true,value = "用户实体")
    private String addUser(@RequestBody User user){
        if (userService.add(user)!=0){
            return "success";
        }
        return "failed";
    }
}
